package com.jinmdz.app.dao.dao.provider;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.jdbc.SQL;

/**
 * 遗体装棺provider
 *
 * @author JiYanJiang
 * @date 2020-08-24 15:37
 */
public class CoffinProvider {
    /**
     * 通过业务编码获得纸棺信息
     *
     * @param businessCode
     * @param businessType
     * @return java.lang.String
     * @author JiYanJiang
     * @date 2020-08-25 13:38
     */
    public String getCoffinByBusinessCode(@Param("businessCode") String businessCode, @Param("businessType") String businessType) {
        return new SQL() {
            {
                StringBuilder builder = new StringBuilder();
                builder.append("charge_item.id,charge_item.version,business_code,");
                builder.append("service_business_item.service_item_id,service_item.item_name,as_unsettled,as_settled ");
                SELECT(builder.toString());
                FROM(" charge_item ");
                JOIN(" service_item ON service_item.id = charge_item.service_item_id ");
                JOIN(" service_business_item ON service_business_item.service_item_id = charge_item.service_item_id ");
                WHERE("charge_item.deleted = 0 AND service_item.deleted = 0 AND service_business_item.deleted = 0 ");
                WHERE(" charge_item.business_code = #{businessCode} ");
                WHERE(" service_business_item.business_type = #{businessType} ");
                ORDER_BY("service_item.sort DESC LIMIT 1");
            }
        }.toString();
    }

    /**
     * 通过业务编码获得确认装棺信息
     *
     * @param businessCode
     * @return java.lang.String
     * @author JiYanJiang
     * @date 2020-08-25 13:39
     */
    public String getCoffinConfirmByBusinessCode(@Param("businessCode") String businessCode) {
        return new SQL() {
            {
                StringBuilder builder = new StringBuilder();
                builder.append("id,version,business_code,service_item_id,qr_code,random_code,charge_id");
                SELECT(builder.toString());
                FROM(" coffin_confirm ");
                WHERE("coffin_confirm.deleted = 0 ");
                WHERE("business_code = #{businessCode} ");
            }
        }.toString();
    }
}
